<%-- 
    Document   : ChangePassword
    Created on : May 7, 2014, 2:55:51 PM
    Author     : mishra
--%>

<%
    try {
        if (session.getAttribute("uid") != null) {
%>
<%String to = "", status = "", msg = "";%>
<!DOCTYPE html>
<html>
    <head>
        <title>Ramgovind Automated System</title>

        <link rel="stylesheet" href="/RIT/css/bootstrap.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap-responsive.css">
        <link rel="stylesheet" href="/RIT/css/jquery.fancybox.css">
        <link rel="stylesheet" href="/RIT/css/style.css">
        <link rel="stylesheet" href="/RIT/css/iconfont.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap.datepicker.css">
        <script>
            function matchPass(pass, uId)
            {
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        var rest=xmlhttp.responseText;
                        if(rest==1){
                            document.getElementById('passmsg').innerHTML ='<div class="alert alert - info alert - block"><a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a><h4 class="alert-heading"> Success</h4>Password Matched!</div>';
                            document.getElementById('subbtn').disabled=false;
                        }
                        else if(rest==0){
                            document.getElementById('passmsg').innerHTML ='<div class="alert alert - info alert - block"><a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a><h4 class="alert-heading"> Fail</h4>Password Not Matched!</div>';
                            document.getElementById('subbtn').disabled=true;
                        }
                    }
                }
                xmlhttp.open("POST", "/RIT/MatchPassword?pass=" + pass + "&uidd=" + uId, true);
                xmlhttp.send();
            }
        </script>

    </head>
    <body>
        <%@include file="/Student/topheaderstu.html" %>
        <%@include file="/Student/servicesheaderstu.html" %>
        <div class="main">
            <div class="container-fluid">
                <%@include file="/Student/profilesidenavstu.html" %>
                <div class="content">
                    <%if (session.getAttribute("status") != null) {
                            status = session.getAttribute("status").toString();
                            msg = session.getAttribute("msg").toString();
                    %>
                    <div class="alert alert-success alert-block">
                        <a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a>
                        <h4 class="alert-heading"> <%=status%></h4>
                        <%=msg%>

                    </div>
                    <%session.removeAttribute("status");
                            session.removeAttribute("msg");
                        }%>
                    <div id="passmsg">

                    </div>
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="box">
                                <div class="box-head">
                                    <h3>Change Password</h3>
                                </div>

                                <form action="/RIT/ChangePasswordStu" method="post" class='validate form-horizontal'>
                                    <div class="box-content">
                                        <!---Form Start....-->
                                        <div id="midd" style="float: inside; margin-top: 10px; width: 48%;">
                                            <div class="control-group">
                                                <label for="coname" class="control-label">Password<span style="color:red">*</span></label>
                                                <div class="controls">
                                                    <input type="text" name="coname" id="coname" class='required' onblur="matchPass(this.value, document.getElementById('uidd').value)">
                                                    <input type="hidden" name="uidd" id="uidd" class='required' value="<%=session.getAttribute("uid")%>">
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label for="password" class="control-label">New Password<span style="color:red">*</span></label>
                                                <div class="controls">
                                                    <input type="password" name="pwd" id="pwd" class='required' minlength="6">
                                                    <span id="result"></span>
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label for="cpassword" class="control-label">Confirm Password<span style="color:red">*</span></label>
                                                <div class="controls">
                                                    <input type="password" name="cpwd" id="cpwd" class='required' equalto="#pwd">
                                                </div>
                                            </div>
                                        </div>
                                        <!---Form Ends....-->
                                    </div>
                                    <div class="form-actions">
                                        <input type="submit" id="subbtn" name="subbtn" class='btn btn-primary'>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                </div>	
            </div>
        </div>

        <script src="/RIT/js/jquery.js"></script>
        <script src="/RIT/js/less.js"></script>
        <script src="/RIT/js/bootstrap.min.js"></script>
        <script src="/RIT/js/jquery.uniform.min.js"></script>
        <script src="/RIT/js/bootstrap.timepicker.js"></script>
        <script src="/RIT/js/bootstrap.datepicker.js"></script>
        <script src="/RIT/js/chosen.jquery.min.js"></script>
        <script src="/RIT/js/jquery.fancybox.js"></script>
        <script src="/RIT/js/plupload/plupload.full.js"></script>
        <script src="/RIT/js/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
        <script src="/RIT/js/jquery.cleditor.min.js"></script>
        <script src="/RIT/js/jquery.inputmask.min.js"></script>
        <script src="/RIT/js/jquery.tagsinput.min.js"></script>
        <script src="/RIT/js/jquery.mousewheel.js"></script>
        <script src="/RIT/js/jquery.textareaCounter.plugin.js"></script>
        <script src="/RIT/js/ui.spinner.js"></script>
        <script src="/RIT/js/jquery.jgrowl_minimized.js"></script>
        <script src="/RIT/js/jquery.form.js"></script>
        <script src="/RIT/js/jquery.validate.min.js"></script>
        <script src="/RIT/js/bbq.js"></script>
        <script src="/RIT/js/jquery-ui-1.8.22.custom.min.js"></script>
        <script src="/RIT/js/jquery.form.wizard-min.js"></script>
        <script src="/RIT/js/jquery.cookie.js"></script>
        <script src="/RIT/js/jquery.metadata.js"></script>
        <script src="/RIT/js/custom.js"></script><script src="/RIT/js/demo.js"></script>
        <script src="/RIT/js/iconfont.js"></script>
        <script>
                                                        /*
                                                         jQuery document ready.
                                                         */
                                                        $(document).ready(function()
                                                        {
                                                            /*assigning keyup event to password field so everytime user type code will execute */
                                                            $('#pwd').keyup(function()
                                                            {
                                                                $('#result').html(checkStrength($('#pwd').val()))
                                                            })

                                                            /* checkStrength is function which will do the main password strength checking for us */

                                                            function checkStrength(password)
                                                            {
                                                                //initial strength
                                                                var strength = 0

                                                                //if the password length is less than 6, return message.
                                                                if (password.length < 6) {
                                                                    $('#result').removeClass()
                                                                    $('#result').addClass('short')
                                                                    return 'Too short'
                                                                }
                                                                //length is ok, lets continue.

                                                                //if length is 8 characters or more, increase strength value
                                                                if (password.length > 7)
                                                                    strength += 1

                                                                //if password contains both lower and uppercase characters, increase strength value
                                                                if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))
                                                                    strength += 1

                                                                //if it has numbers and characters, increase strength value
                                                                if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))
                                                                    strength += 1

                                                                //if it has one special character, increase strength value
                                                                if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))
                                                                    strength += 1

                                                                //if it has two special characters, increase strength value
                                                                if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/))
                                                                    strength += 1

                                                                //now we have calculated strength value, we can return messages

                                                                //if value is less than 2
                                                                if (strength < 2)
                                                                {
                                                                    $('#result').removeClass()
                                                                    $('#result').addClass('weak')
                                                                    return 'Weak'
                                                                }
                                                                else if (strength == 2)
                                                                {
                                                                    $('#result').removeClass()
                                                                    $('#result').addClass('good')
                                                                    return 'Good'
                                                                }
                                                                else
                                                                {
                                                                    $('#result').removeClass()
                                                                    $('#result').addClass('strong')
                                                                    return 'Strong'
                                                                }
                                                            }
                                                        });

        </script>
        <style>
            .short{
                color:#FF0000;
            }
            .weak{
                color:#E66C2C;
            }
            .good{
                color:#2D98F3;
            }
            .strong{
                color:#006400;
            }
        </style>
    </body>
</html>

<%
        } else {
            request.setAttribute("msg", "You Are Not Authorised! Please Contact to System Administrator!");
            request.setAttribute("value", "0");
            getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
        }
    } catch (Exception e) {
        request.setAttribute("msg", "Please Contact to System Administrator!");
        request.setAttribute("value", "0");
        getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    }
%>